<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
	<title>中签图片上传</title>
	<script src="__STATIC__/js/jquery-2.1.4.min.js" type="text/javascript"></script>
	<style type="text/css">
		.uploadinput{
			z-index: 2;
		    position: absolute;
		    left: 0;
		    top: 0;
		    width: 100%;
		    height: 150px;
		    opacity: .01;
		    filter: alpha(opacity=1);
		    cursor: pointer;
		}
	</style>
</head>

<body>
    <h1>图片上传</h1>
    <div>
		<table>
			<tr>
				<th width="100">中签号</th>
				<th width="100">姓名</th>
				<th width="200">上课地点</th>
				<th width="">图片</th>
			</tr>
			<tbody id="result">
			
			</tbody>
		</table>
	</div>
</body>
<script type="text/javascript">
	var url = "/zhaosheng/zhao_sheng";
	query();
	function query() {
		$.ajax({
		   type:"GET",
		   url: url + "/getList",
		   data:{},
		   success: function(resp){
				var html = "";
				if(resp != null) {
					for(var i in resp) {
						html+="<tr align='center'><td>"+resp[i].中签号+"</td><td>"+resp[i].姓名+"</td><td>"+resp[i].上课地点+"</td><td>"+(resp[i].图片 ? '<img style="width:50px" src="__UPLOAD__/'+resp[i].图片+'?v='+new Date().getTime()+'"/><input class="uploadinput" type="file" onChange="fileup(this,'+resp[i].中签号+')"/>' : '<input type="file" onChange="fileup(this,'+resp[i].中签号+')"/>')+"</td></tr>";
					}
				}
				$("#result").html(html);
		   }
		});
	}
　　function fileup(e,zqh){
        var files = e.files;
        if(!(files && files[0])) {
        	return;
        }
       	var formData = new FormData();
    	formData.append("image", files[0]);
    	formData.append("zqh",zqh);
    	$.ajax({
        	url: url + '/uploadImg',
        	type: 'POST',
        	data: formData,
        	processData: false,
        	contentType: false, 
        	dataType: 'json',
        	success:function (res) {
            	if(res.code == '000') {
            		query();
            		alert("上传成功");
            	}else {
            		alert(res.data);
            	}
       		},error:function (res) {
       			console.log(res);
            	alert("上传异常");
        	}
        });
    }
</script>

</html>
